package com.gitee.wsl.mathematics.geometry.d2.line

import com.gitee.wsl.io.dataproxy.asProxy
import com.gitee.wsl.mathematics.coordinate.polar.ext.polar
import com.gitee.wsl.mathematics.geometry.d2.AbstractShape
import com.gitee.wsl.mathematics.geometry.d2.base.YPolarity
import com.gitee.wsl.mathematics.geometry.d2.contour.ShapeContour
import com.gitee.wsl.mathematics.geometry.d2.rect.Rectangle
import com.gitee.wsl.mathematics.vector.vec2.Vec2f
import com.gitee.wsl.unit.angle.AngleUnit


open class Line(a: Vec2f, b: Vec2f) : AbstractShape(arrayOf(a,b).asProxy()),
    LineShape2d<Float, Vec2f> {
    constructor(x:Number,y:Number,x1:Number,y1:Number):this(Vec2f(x,y),Vec2f(x1,y1))
    override val area: Float = 0f

    companion object{
        val ZERO = Line(Vec2f.ZERO, Vec2f.ZERO)
        //val NaN = Line(Vec2f.NaN, Vec2f.NaN)

        fun fromPointAndDirection(point: Vec2f, direction: Vec2f, scale: Float = 1.0f): Line =
            Line(point, point + direction * scale)

        fun fromPointAngle(point: Vec2f, angle: AngleUnit, length: Float = 1.0f): Line =
            Line(point, polar(angle, length))
    }

    override fun create(a: Vec2f, b: Vec2f) = Line(a,b)

    override fun createPoint2(x: Float, y: Float) = Vec2f(x,y)

    override fun getBounds() = Rectangle(a,b)

    /** Returns [ShapeContour] representation of the [LineSegment]. */
    override val contour: ShapeContour
        get() = ShapeContour.fromPoints(listOf(start, end), false, YPolarity.CW_NEGATIVE_Y)

}